<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title><{$title}></title>

    <link rel="stylesheet" href="<{$smarty.const._CDN_}>/resource/app/css/style.css?<{$versionCode}>">
    <link rel="stylesheet" href="<{$smarty.const._CDN_}>/resource/skin/css/style_extra.css?<{$versionCode}>">
    <link rel="shortcut icon" type="image/x-icon" href="/icon.ico">

    <script src="<{$smarty.const._CDN_}>/resource/app/js/jquery-2.1.4.min.js"></script>
    <script src="<{$smarty.const._CDN_}>/resource/skin/js/jquery.blockUI.js"></script>
    <script src="<{$smarty.const._CDN_}>/resource/app/js/hammer.min.js"></script>
    <script src="<{$smarty.const._CDN_}>/resource/app/js/common.js"></script>


<script>

// 全局javascipt 变量

var global_user_uid  = <{$global_user.userUid}>;
var global_item_type = <{if $global_item}>'<{$global_item.type}>'<{else}>''<{/if}>;
var global_item_nid  = <{if $global_item}>'<{$global_item.nid}>'<{else}>''<{/if}>;
var global_item_countsLike  = <{if $global_item}>'<{$global_item.countsLike}>'<{else}>''<{/if}>;
var global_item_isLiked  = <{if $global_item && $global_item.isLiked}>1<{else}>0<{/if}>;

// 回调函数
function user_logout()
{
    window.youzi.client_user_logout();
}

function user_login()
{
    window.location.assign('/login');
    //window.youzi.client_user_login();
}

function user_message_click (msgItem)
{
    uid = user_get_uid();
    if (uid > 0)
    {
        url = $(msgItem).attr('url');
        window.youzi.client_user_message_click(url);
    }
    else
    {
        user_login();
    }
}

function user_get_uid()
{
    return global_user_uid;
    try {
        return window.youzi.client_user_uid();
    } catch (e)
    {
        return 0;
    }
}

function user_reset_avatar()
{
    return window.youzi.client_user_reset_avatar();
}

function chat_init_user ()
{
    uid = user_get_uid();
    if (uid > 0)
    {
        var user = "user" + uid;
        var pass = "youzi";

        window.youzi.client_chat_set_user(user, pass);
    }
    else
    {
        window.youzi.client_chat_clean_user();
    }
}

function chat_need_user_login ()
{
    uid = user_get_uid();
    if (uid > 0)
    {
        var user = "user" + uid;
        var pass = "youzi";
        var userAvatar = "<{$global_user.userIcon}>";
        //var userAvatar = "https://tower.im/assets/default_avatars/winter.jpg";
        try {
            window.youzi.client_chat_set_user(user, pass);
        } catch (e) {
            window.youzi.client_chat_set_user(user, pass, userAvatar);
        }
        
    }
    else
    {
        user_login();
    }
}


function html5_user_like ()
{
    if (global_item_type && global_item_nid)
    {
        user_like(global_item_type, global_item_nid, '');
    }
}

function html5_user_comments ()
{
    if (global_item_type == 'gonglue' && global_item_nid > 0)
    {
        var url = '/m/comments/gonglue/' + global_item_nid + '/1?uid=' + user_get_uid();
        window.location.assign(url);
    }
}

function user_like (type, nid, item)
{
    var uid = user_get_uid();
    if (uid > 0)
    {
        url = '/api/user/like?uid=' + uid;
        $.post(url, {'type' : type, 'nid' : nid}, function (o) {
            if (o && o.status == 0)
            {
                if (typeof(item) == 'object')
                {
                    item = $(item).find('em');
                    if (item.length > 0)
                        item = item.get(0);
	                if ($(item).hasClass('nolike-icon'))
	                {
	                    $(item).removeClass('nolike-icon');
	                    $(item).addClass('like-icon');
	                }
	                else
	                {
	                    $(item).removeClass('like-icon');
	                    $(item).addClass('nolike-icon');
	                }

                    $(item).parent().find('.iCounts').html(o.counts);
                }
                // HTML5内操作
                else if (type == 'goods')
                {
	                if ($(item).hasClass('collect'))
	                {
	                    $(item).removeClass('collect');
	                    $(item).addClass('collected');
	                }
	                else
	                {
	                    $(item).removeClass('collected');
	                    $(item).addClass('collect');
	                }
                }
                // APP内操作
                else
                {
                    window.youzi.client_user_like (o.counts, o.hasLiked);
                }
            }
        }, 'json');
    }
    else
    {
        user_login();
    }
}

function user_follow (type, uid, item)
{
    currentUid = user_get_uid();
    if (currentUid == 0)
    {
        user_login();
        return;
    }

    $.post('/api/user/follow', { type : type , uid : uid }, function (o) {
        if (o && o.status == 0)
        {
            if (type == 'add')
            {
                $(item).parent().html('<em class="yi-add">已关注</em>');
            }
            else
            {
                $(item).parent().parent().remove();
            }
        }
    }, 'json');
}

function user_follow2 (type, uid, item)
{
    $.post('/api/user/follow', { type : type , uid : uid }, function (o) {
        if (o && o.status == 0)
        {
            if (type == 'add')
            {
                $(item).parent().html('<img class="add-attention" onclick="user_follow2(\'del\', '+uid+', this)" src="/resource/app/imgs/yi_attention.png" alt="">');
            }
            else
            {
                $(item).parent().html('<img class="cancel-attention" onclick="user_follow2(\'add\', '+uid+', this)" src="/resource/app/imgs/add_attention.png" alt="">');
            }
        }else if(o && o.status == 1 && o.errmsg == '未登录'){
            window.location.href = '/login';
        }
    }, 'json');
}

function user_follow3 (type, uid, item)
{    
    currentUid = user_get_uid();
    if (currentUid == 0)
    {
        user_login();
        return;
    }
    else if (currentUid == uid)
    {
        return;
    }


    $.post('/api/user/follow', { type : type , uid : uid }, function (o) {
        if (o && o.status == 0)
        {
            if (type == 'add')
            {
                $(item).parent().html('<img class="cancel-attention" onclick="user_follow3(\'del\', '+uid+', this)" src="/resource/app/imgs/yi_attention2.png" alt="">');
            }
            else
            {
                $(item).parent().html('<img class="add-attention" onclick="user_follow3(\'add\', '+uid+', this)" src="/resource/app/imgs/add_attention2.png" alt="">');
            }
        }else if(o && o.status == 1 && o.errmsg == '未登录'){
            window.location.href = '/login';
        }
    }, 'json');
}


function user_like_shop (type, nid, item)
{
    var uid = user_get_uid();
    if (uid > 0)
    {
        url = '/api/user/like_shop?uid=' + uid;
//        console.log(url)
//        console.log(nid)
        $.post(url, {'type' : type, 'nid' : nid}, function (o) {
            if (o && o.status == 0)
            {
                // HTML5内操作
                if (type == 'shop')
                {
                    if ($(item).hasClass('collect'))
                    {
                        $(item).removeClass('collect');
                        $(item).addClass('collected');
                    }
                    else
                    {
                        $(item).removeClass('collected');
                        $(item).addClass('collect');
                    }
                }
                else if (typeof(item) == 'object')
                {
                    if ($(item).hasClass('black'))
                    {
                        $(item).removeClass('black');
                        $(item).addClass('red');
                    }
                    else
                    {
                        $(item).removeClass('red');
                        $(item).addClass('black');
                    }

                    $(item).html(o.counts);
                }
                // APP内操作
                else
                {
                    window.youzi.client_user_like (o.counts, o.hasLiked);
                }
            }
        }, 'json');
    }
    else
    {
        user_login();
    }
}

function app_set_bottom (json_str)
{
    try {
        window.youzi.setBottomBar (json_str);
    } catch (e) {
        //
    }
}

function app_set_title (json_str)
{
    try {
        window.youzi.initTitle (json_str);
    } catch (e) {
        //
    }
}

function app_client_alipay(orderNo, title, desc, moneyYuan, notifyUrl)
{
    try {

        // 支付宝SDK支付
        window.youzi.client_alipay(orderNo, title, desc, moneyYuan, notifyUrl);
    } 
    catch (e)
    {
        // 支付宝移动网站支付
        url = "/payment/alipay/order/" + orderNo;
        window.location.assign(url);
    }
}

function app_client_wechatpay(orderNo, title, desc, moneyYuan, notifyUrl)
{
    try {

        // 微信SDK支付
        moneyFen = parseInt(parseFloat(moneyYuan) * 100);
        moneyFen = '' + moneyFen;
        window.youzi.client_wechatpay(orderNo, title, desc, moneyFen, notifyUrl);
    } 
    catch (e)
    {
        url = "/payment/weixin/order?orderNo=" + orderNo;
        window.location.assign(url);
    }
}

function user_create_show (uid, orderId, orderNo) 
{
    try {
        window.youzi.client_open_shaidan(uid, orderId, orderNo);
    }
    catch (e)
    {
        // web 版本创建晒单
        url = "/show/create/" + orderNo;
        window.location.assign(url);
    }
}

function html5_user_init_share ()
{
    var title = window.document.title;
     <{if $goods && $goods.images|@count > 0  && $shareType && $shareType == 'goods_detail'}>
    var image   = 'http://www.youzigouwu.com<{$goods.images.0}>';
    var title = '<{$shareTitle}>';
    var message = '[' + title + ']' ;
    <{elseif $topic && $topic.image}>
    var image   = 'http://www.youzigouwu.com<{$topic.image}>';
    var title = '<{$shareTitle}>';
    var message = '[' + title + ']' + '<{$shareDesc}>';
    <{elseif $shop && $shop.shopName}>
    var image   = 'http://www.youzigouwu.com<{$shop.shopIcon}>';
    var title = '<{$shareTitle}>';
    var message = '[' + title + ']' + '<{$shareDesc}>';
    <{elseif $shareType == 'tuan_detail'}>
    var image   = 'http://www.youzigouwu.com<{$goods.thumbsrc}>';
    var title = '我参加了柚子购物的拼团 [<{$shareTitle}>]';
    var message = '我参加了柚子购物的拼团 [<{$shareTitle}>]';
    <{elseif $shareType == 'show_detail'}>
    var image   = 'http://www.youzigouwu.com<{$detail.images.0}>';
    var title = '<{$shareTitle}>';
    var message = '[' + title + ']';
    <{else}>
    var image   = 'http://www.youzigouwu.com/resource/skin/img/system_avatar.png';
    var title = window.document.title;
    var message = '[' + title + ']' + "这是内容";
    <{/if}>
    var pageUrl  = window.location.href;
    var siteUrl = 'http://www.youzigouwu.com';
    window.youzi.client_user_share(title, message, image, pageUrl, siteUrl);

    var uid = user_get_uid();
    if (uid > 0)
    {
        url = '/api/user/share?uid=' + uid;
        $.post(url, {'type' : global_item_type, 'nid' : global_item_nid}, function (o) {
            //
        });
    }
}

$(document).ready(function(){
 
    //var json_str1 = '{"left_type": "back","left_display": "block","title": "test","right_type": "message","right_display": "block","right_text": ""}';
    //var json_str2 = '{"display": "block","position": "homepage"}';
    
    var json_str1 = '<{$title_json}>';
    var json_str2 = '<{$bottom_json}>';
    
    try {
        window.youzi.initTitle (json_str1);
        window.youzi.setBottomBar (json_str2);
        chat_init_user();
    } catch (e){
        //
    }
});

(function ($) {
    $.extend({
        Request: function (m) {
            var sValue = location.search.match(new RegExp("[\?\&]" + m + "=([^\&]*)(\&?)", "i"));
            return sValue ? sValue[1] : sValue;
        },
        UrlUpdateParams: function (url, name, value) {
            var r = url;
            if (r != null && r != 'undefined' && r != "") {
                value = encodeURIComponent(value);
                var reg = new RegExp("(^|)" + name + "=([^&]*)(|$)");
                var tmp = name + "=" + value;
                if (url.match(reg) != null) {
                    r = url.replace(eval(reg), tmp);
                }
                else {
                    if (url.match("[\?]")) {
                        r = url + "&" + tmp;
                    } else {
                        r = url + "?" + tmp;
                    }
                }
            }
            return r;
        }




    });
})(jQuery);

</script>

</head>

<body>
